Skip to content

bugfix: Index properly when dependencyModules is empty - #8787

Merged
tgodzik merged 1 commit into
scalameta:main-v2from
tgodzik:remove-workaround
Aug 12, 2026
Merged

bugfix: Index properly when dependencyModules is empty#8787
tgodzik merged 1 commit into
scalameta:main-v2from
tgodzik:remove-workaround

Conversation

@tgodzik

@tgodzik tgodzik commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

There were two issues here, which together broke go to def for dependency sources in Scala CLI:

  • we had a check to not run the request for Scala CLI (due to some previous native image issues)
  • without dependency modules nothing would be indexed

Now, we remove the workaround as the Scala CLI issue is now solved, but also added a fallback just in case

Summary by CodeRabbit

  • Bug Fixes
    • Improved “Go to Definition” support for Scala library and dependency symbols when dependency metadata is unavailable or incomplete.
    • Added fallback indexing from dependency classpath JARs, including matching source JARs when available.
    • Improved dependency indexing support for Scala CLI projects.
    • Added warnings when dependency source files cannot be found, helping explain incomplete navigation results.
    • Improved reliability when dependency information is missing or dependency module lists are empty.

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 052b6f92-d72c-401d-b593-097759b2a158

📥 Commits

Reviewing files that changed from the base of the PR and between 3e4da1f and bef83a5.

📒 Files selected for processing (1)
  • tests/unit/src/main/scala/bill/Bill.scala
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/unit/src/main/scala/bill/Bill.scala

📝 Walkthrough

Walkthrough

The indexer now falls back to target classpath jars when dependency modules are absent or empty. It associates source jars, derives Scala dialects, and adds dependency modules. Build server capability reporting and Bill test support were updated. Tests verify Scala library definition lookup.

Changes

Dependency module fallback

Layer / File(s) Summary
Capability and test support
metals/src/main/scala/scala/meta/internal/metals/buildserver/BuildServerConnection.scala, tests/unit/src/main/scala/bill/Bill.scala
Dependency-module capability reporting no longer excludes Scala CLI. Bill returns empty dependency-module results asynchronously.
Classpath fallback indexing
metals/src/main/scala/scala/meta/internal/metals/Indexer.scala
When dependency modules are absent and classpath indexing is enabled, the indexer processes unique target classpath jars, matching source jars, placeholder Maven coordinates, and derived Scala dialects.
Definition lookup validation
tests/unit/src/test/scala/tests/BillLspSuite.scala
The tests verify that List resolves to the Scala library when dependency modules are absent or empty.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant BuildServerConnection
  participant Bill
  participant Indexer
  participant DefinitionIndex
  BuildServerConnection-->>Indexer: dependency-modules capability
  Bill-->>Indexer: empty dependency-module result
  Indexer->>Indexer: read and deduplicate classpath jars
  Indexer->>DefinitionIndex: index fallback jars
  DefinitionIndex-->>Indexer: resolve Scala List definition
Loading

Possibly related PRs

  • scalameta/metals#8352: Both changes update how Indexer.scala uses definitionIndexStrategy for dependency and classpath indexing.

Suggested reviewers: zielinsky

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: indexing dependencies when dependencyModules is empty.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@metals/src/main/scala/scala/meta/internal/metals/Indexer.scala`:
- Around line 268-278: Update the dependency indexing flow in Indexer to retain
the set returned by indexDependencyModules and trigger
indexClasspathJarsFallback when that set is empty, rather than checking only
dependencyModules target items. Preserve the isClasspathIndexing guard, and add
a regression case covering a nonempty DependencyModulesResult whose module lists
are empty.

In `@tests/unit/src/main/scala/bill/Bill.scala`:
- Around line 404-410: Update buildInitialize to call
capabilities.setDependencyModulesProvider(true), so BuildServerConnection
advertises and routes dependency-module requests to
Bill.buildTargetDependencyModules instead of returning its local empty result.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 57d2ee77-fb08-4fc3-93c7-a5af81616337

📥 Commits

Reviewing files that changed from the base of the PR and between 1970dff and 6d52eab.

📒 Files selected for processing (4)
  • metals/src/main/scala/scala/meta/internal/metals/Indexer.scala
  • metals/src/main/scala/scala/meta/internal/metals/buildserver/BuildServerConnection.scala
  • tests/unit/src/main/scala/bill/Bill.scala
  • tests/unit/src/test/scala/tests/BillLspSuite.scala

Comment thread metals/src/main/scala/scala/meta/internal/metals/Indexer.scala
Comment thread tests/unit/src/main/scala/bill/Bill.scala
@tgodzik
tgodzik force-pushed the remove-workaround branch from 6d52eab to 3e4da1f Compare August 12, 2026 12:15
There were two issues here, which together broke go to def for dependency sources in Scala CLI:
- we had a check to not run the request for Scala CLI (due to some previous native image issues)
- without dependency modules nothing would be indexed

Now, we remove the workaround as the Scala CLI issue is now solved, but also added a fallback just in case
@tgodzik
tgodzik force-pushed the remove-workaround branch from 3e4da1f to bef83a5 Compare August 12, 2026 12:43
@tgodzik
tgodzik merged commit 1e682fe into scalameta:main-v2 Aug 12, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant